<?php

namespace app\shop\model\company;

use think\Model;
use app\shop\model\user\User;
use app\shop\model\shop\User as ShopUser;
use app\shop\model\file\UploadFile;
use think\model\concern\SoftDelete;
/**
 * 应用模型
 */
class StudyFile extends Model
{
    use SoftDelete;
    protected $autoWriteTimestamp = true;

    const TYPE_EXPIRE = 1;    //学习心得
    const TYPE_VIDEO = 2;    //视频
    const TYPE_DOCUMENT = 3;    //文档

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'user_id');
    }

    public function staff()
    {
        return $this->belongsTo(Staff::class, 'user_id', 'user_id');
    }

    public function admin()
    {
        return $this->belongsTo(ShopUser::class, 'checker', 'shop_user_id');
    }

    public function file()
    {
        return $this->belongsTo(UploadFile::class, 'file_id', 'file_id');
    }

    public function getStatusTextAttr($value, $data)
    {
        $status = [
            0 => '未审核',
            1 => '已审核',
            2 => '已拒绝',
        ];
        return $status[$data['status']];
    }

    public function getTypeTextAttr($value, $data)
    {
        $status = [
            self::TYPE_EXPIRE => '学习心得',
            self::TYPE_VIDEO => '视频教程',
            self::TYPE_DOCUMENT => '文档资料',
        ];
        return $status[$data['type']];
    }
}
